import st from "./showtoast.js";
import env from "../utlis/env.js";


/**
 * 上传图片
 */
export let upload = (file) => {
	uni.showLoading({
		title: ""
	})
	let promise = new Promise((success, fail) => {
		uni.uploadFile({
			filePath: file,
			name: "file",
			header: {
				token: uni.getStorageSync("token") || "",
			},
			url: env.baseUrl + "/api/common/upload",
			success(res) {
				let data = JSON.parse(res.data)
				if (data.code == 1) {
					success(data)
				} else {
					st.show(data.msg)
					fail(data)
				}
			},
			fail: res => {
				fail(res)
			},
			complete: () => {
				uni.hideLoading()
			}
		})
	})
	return promise
}

module.exports = {
	upload
}